<?php
namespace Admin\Controller;
use Think\Controller;
class AuthController extends Controller {
	//角色列表
	public function auth_list(){
		$auth=D('auth');

		$count = $auth -> count(); // 查询满足要求的总记录数
		$Page = new\ Think\ Page($count, 10); 
		// 实例化分页类 传入总记录数和每页显示的条数
		$Page->setConfig('theme', '<li><a>共 %TOTAL_ROW% 条记录</a> %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% ');
		$show       = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出            		
		$list = $auth -> order('id ASC') -> limit($Page -> firstRow.','.$Page -> listRows) -> select();
		$this -> assign('authlist', $list); // 赋值数据集		
		$this -> display();	
	}
	//角色添加
	public function auth_add(){
		$auth=D('auth');
		if(IS_POST){
			$authdata['authname']=I('authname');
			if($auth->data($authdata)->add()){
				$this->success('添加角色成功',U('auth_list'));	
			}else{
				$this->error('添加角色失败~！');
			}
		}else{
			$this->display();
		}
	}
	//角色修改
	public function auth_edit(){
		$auth=D('auth');
		$authdata['id']=I('id');
		if(IS_POST){
			$authdata['authname']=I('authname');
			$save=$auth->save($authdata);
			if($save !==false){
				$this->success('修改成功~！',U('auth_list'));
			}else{
				$this->error('修改角色失败~！');
			}
		}else{
			$authfind=$auth->find($authdata['id']);
			$this->assign('authfind',$authfind);
			$this->display();
		}
	}
	//角色删除
	public function auth_del(){
		$auth=D('auth');
		$authdata['id']=I('id');
		if($auth->delete($authdata['id'])){
			$this->success('删除成功~!',U('auth_list'));
		}else{
			$this->error('删除失败~！');
		}
	}
	//批量删除
	public function auth_del_all(){

        $ids = I('id');
        $where['id']=array("in",$ids);

        if(empty($ids)){
             $this->error("非法操作！");
        }else{
        	$auth_delall = M('auth')->where($where)->delete();
	        if ($auth_delall !== false) {
	             $this->success('删除成功',U('auth_list'));
	        }else{
	             $this->error('删除失败');
	        }	
        }	
	}
}
?>